/**
 * tarside-ftp -- A simple FTP client, using the ANSI C and GTK+.
 * Copyright (C) 2011  degui.chen <degui.chen@qq.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "popup_menu.h"
static GtkWidget* menu;
static gint button_press(GtkWidget *widget, GdkEvent *event) {
	if (event->type == GDK_BUTTON_PRESS) {
		GdkEventButton *bevent = (GdkEventButton *) event;
		if (bevent->button == 3) {
			gtk_menu_popup(GTK_MENU(widget), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
			return TRUE;
		}
	}
	return FALSE;
}
static void menuitem_response(gchar *string) {
	printf("%s\n", string);
}

void test_create_menu_items() {
	int i;
	for (i = 0; i < 3; i++) {
		char buf[128];
		sprintf(buf, "Test-undermenu - %d", i); /* 将名称复制到buf. */
		create_menu_item(buf, &menuitem_response);
	}
}
void create_menu_item(char buf[256], popup_menu_item_hander hander) {
	GtkWidget *menu_items;
	menu_items = gtk_menu_item_new_with_label(buf);
	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_items);
	g_signal_connect_swapped(G_OBJECT(menu_items), "activate", G_CALLBACK(hander), g_strdup(buf));
	gtk_widget_show(menu_items);
}

void PopupMenu(GtkWidget *button) {
	menu = gtk_menu_new();
	//test_create_menu_items();
	g_signal_connect_swapped(G_OBJECT(button), "event", G_CALLBACK(button_press), menu);
}

